#include "stdafx.h"
#include "TestAnimation.h"


TestAnimation::TestAnimation()
{
	animstate = NULL;
}

TestAnimation::~TestAnimation()
{

}

void TestAnimation::OnStart()
{
	m_SceneManager->setAmbientLight(ColourValue(1.0f, 1.0f, 1.0f));
	Entity* ent = m_SceneManager->createEntity("dog","dog.mesh");
	SceneNode*	node = m_SceneManager->getRootSceneNode()->
					createChildSceneNode("EntityNode", Vector3(0.0f, 0.0f, 25.0f));

	node->attachObject(ent);
	node->scale(20,20,20);
	
	Vector3 pos = node->getPosition();

	m_Camera->setPosition(90.0f, 280.0f, 535.0f);
	m_Camera->lookAt(pos.x, pos.y, pos.z);

	skinst = ent->getSkeleton();
	if (!skinst)
		return;

	animstate = ent->getAnimationState("idle");
	animstate->setLoop(true);
	animstate->setEnabled(true);
}

void TestAnimation::OnStop()
{

}

void TestAnimation::OnEvent(Event* evt)
{

	BEGIN_EVENT_HANDLER(evt);

	ON_EVENT(FrameUpdatedEvent)
	{
		if (animstate)
			animstate->addTime(evt->DT);
	}

	END_EVENT_HANDLER;
}

REGISTER_GAMESESSION("TestAnimation", TestAnimation);

